<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Classes  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset="utf-8">
    <script src="js/jquery.min.js" defer></script>
    <script src="js/jazzy.js" defer></script>
    
    <script src="js/lunr.min.js" defer></script>
    <script src="js/typeahead.jquery.js" defer></script>
    <script src="js/jazzy.search.js" defer></script>
  </head>
  <body>

    <a name="//apple_ref/swift/Section/Classes" class="dashAnchor"></a>

    <a title="Classes  Reference"></a>

    <header class="header">
      <p class="header-col header-col--primary">
        <a class="header-link" href="index.html">
          SwiftJWT 3.6.200 Docs
        </a>
         (100% documented)
      </p>
    
      <p class="header-col--secondary">
        <form role="search" action="search.json">
          <input type="text" placeholder="Search documentation" data-typeahead>
        </form>
      </p>
    
        <p class="header-col header-col--secondary">
          <a class="header-link" href="https://github.com/Kitura/Swift-JWT/">
            <img class="header-icon" src="img/gh.png"/>
            View on GitHub
          </a>
        </p>
    
    </header>

    <p class="breadcrumbs">
      <a class="breadcrumb" href="index.html">SwiftJWT Reference</a>
      <img class="carat" src="img/carat.png" />
      Classes  Reference
    </p>

    <div class="content-wrapper">
      <nav class="navigation">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Classes.html">Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/ClaimsMicroProfile.html">ClaimsMicroProfile</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/ClaimsOpenID.html">ClaimsOpenID</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/ClaimsStandardJWT.html">ClaimsStandardJWT</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/JWTDecoder.html">JWTDecoder</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Classes/JWTEncoder.html">JWTEncoder</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Protocols.html">Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Protocols/Claims.html">Claims</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a class="nav-group-name-link" href="Structs.html">Structures</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/AddressClaim.html">AddressClaim</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/Header.html">Header</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/JWT.html">JWT</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/JWTError.html">JWTError</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/JWTSigner.html">JWTSigner</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/JWTVerifier.html">JWTVerifier</a>
              </li>
              <li class="nav-group-task">
                <a class="nav-group-task-link" href="Structs/ValidateClaimsResult.html">ValidateClaimsResult</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">

        <section class="section">
          <div class="section-content top-matter">
            <h1>Classes</h1>
            <p>The following classes are available globally.</p>

          </div>
        </section>

        <section class="section">
          <div class="section-content">
            <div class="task-group">
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:8SwiftJWT18ClaimsMicroProfileC"></a>
                    <a name="//apple_ref/swift/Class/ClaimsMicroProfile" class="dashAnchor"></a>
                    <a class="token" href="#/s:8SwiftJWT18ClaimsMicroProfileC">ClaimsMicroProfile</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>A class representing the MicroProfile claims as listed in <a href="http://microprofile.io/project/eclipse/microprofile-jwt-auth/spec/src/main/asciidoc/interoperability.asciidoc">MicroProfile specs</a>.</p>

                        <a href="Classes/ClaimsMicroProfile.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">ClaimsMicroProfile</span> <span class="p">:</span> <span class="kt"><a href="Protocols/Claims.html">Claims</a></span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:8SwiftJWT12ClaimsOpenIDC"></a>
                    <a name="//apple_ref/swift/Class/ClaimsOpenID" class="dashAnchor"></a>
                    <a class="token" href="#/s:8SwiftJWT12ClaimsOpenIDC">ClaimsOpenID</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>A class representing OpenID related claims as decsribed in <a href="http://openid.net/specs/openid-connect-core-1_0.html">OpenID specs</a>.</p>

                        <a href="Classes/ClaimsOpenID.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">ClaimsOpenID</span> <span class="p">:</span> <span class="kt"><a href="Protocols/Claims.html">Claims</a></span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:8SwiftJWT014ClaimsStandardB0C"></a>
                    <a name="//apple_ref/swift/Class/ClaimsStandardJWT" class="dashAnchor"></a>
                    <a class="token" href="#/s:8SwiftJWT014ClaimsStandardB0C">ClaimsStandardJWT</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>A class representing the Standard JWT claims as described in <a href="https://tools.ietf.org/html/rfc7519#section-4.1">RFC7519</a>.</p>

                        <a href="Classes/ClaimsStandardJWT.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">ClaimsStandardJWT</span> <span class="p">:</span> <span class="kt"><a href="Protocols/Claims.html">Claims</a></span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/JWTEncoder"></a>
                <a name="//apple_ref/swift/Section/JWTEncoder" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/JWTEncoder"></a>
                  <h3 class="section-name"><p>JWTEncoder</p>
</h3>
                </div>
              </div>
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:8SwiftJWT10JWTEncoderC"></a>
                    <a name="//apple_ref/swift/Class/JWTEncoder" class="dashAnchor"></a>
                    <a class="token" href="#/s:8SwiftJWT10JWTEncoderC">JWTEncoder</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>A thread safe encoder that signs the JWT header and claims using the provided algorithm and encodes a <code><a href="Structs/JWT.html">JWT</a></code> instance as either Data or a JWT String.</p>
<h3 id='usage-example' class='heading'>Usage Example:</h3>
<pre class="highlight swift"><code><span class="kd">struct</span> <span class="kt">MyClaims</span><span class="p">:</span> <span class="kt">Claims</span> <span class="p">{</span>
   <span class="k">var</span> <span class="nv">name</span><span class="p">:</span> <span class="kt">String</span>
<span class="p">}</span>
<span class="k">var</span> <span class="nv">jwt</span> <span class="o">=</span> <span class="kt">JWT</span><span class="p">(</span><span class="nv">claims</span><span class="p">:</span> <span class="kt">MyClaims</span><span class="p">(</span><span class="nv">name</span><span class="p">:</span> <span class="s">"John Doe"</span><span class="p">))</span>
<span class="k">let</span> <span class="nv">privateKey</span> <span class="o">=</span> <span class="s">"&lt;PrivateKey&gt;"</span><span class="o">.</span><span class="nf">data</span><span class="p">(</span><span class="nv">using</span><span class="p">:</span> <span class="o">.</span><span class="n">utf8</span><span class="p">)</span><span class="o">!</span>
<span class="k">let</span> <span class="nv">rsaJWTEncoder</span> <span class="o">=</span> <span class="kt">JWTEncoder</span><span class="p">(</span><span class="nv">jwtSigner</span><span class="p">:</span> <span class="kt">JWTSigner</span><span class="o">.</span><span class="nf">rs256</span><span class="p">(</span><span class="nv">privateKey</span><span class="p">:</span> <span class="n">privateKey</span><span class="p">))</span>
<span class="k">do</span> <span class="p">{</span>
   <span class="k">let</span> <span class="nv">jwtString</span> <span class="o">=</span> <span class="k">try</span> <span class="n">rsaJWTEncoder</span><span class="o">.</span><span class="nf">encodeToString</span><span class="p">(</span><span class="n">jwt</span><span class="p">)</span>
<span class="p">}</span> <span class="k">catch</span> <span class="p">{</span>
   <span class="nf">print</span><span class="p">(</span><span class="s">"Failed to encode JWT: </span><span class="se">\(</span><span class="n">error</span><span class="se">)</span><span class="s">"</span><span class="p">)</span>
<span class="p">}</span>
</code></pre>

                        <a href="Classes/JWTEncoder.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">JWTEncoder</span> <span class="p">:</span> <span class="kt">BodyEncoder</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
            <div class="task-group">
              <div class="task-name-container">
                <a name="/JWTDecoder"></a>
                <a name="//apple_ref/swift/Section/JWTDecoder" class="dashAnchor"></a>
                <div class="section-name-container">
                  <a class="section-name-link" href="#/JWTDecoder"></a>
                  <h3 class="section-name"><p>JWTDecoder</p>
</h3>
                </div>
              </div>
              <ul class="item-container">
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:8SwiftJWT10JWTDecoderC"></a>
                    <a name="//apple_ref/swift/Class/JWTDecoder" class="dashAnchor"></a>
                    <a class="token" href="#/s:8SwiftJWT10JWTDecoderC">JWTDecoder</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>A thread safe decoder that decodes either Data or a JWT String as a <code><a href="Structs/JWT.html">JWT</a></code> instance and verifies the signiture using the provided algorithm.</p>
<h3 id='usage-example' class='heading'>Usage Example:</h3>
<pre class="highlight swift"><code><span class="kd">struct</span> <span class="kt">MyClaims</span><span class="p">:</span> <span class="kt">Claims</span> <span class="p">{</span>
   <span class="k">var</span> <span class="nv">name</span><span class="p">:</span> <span class="kt">String</span>
<span class="p">}</span>
<span class="k">let</span> <span class="nv">publicKey</span> <span class="o">=</span> <span class="s">"&lt;PublicKey&gt;"</span><span class="o">.</span><span class="nf">data</span><span class="p">(</span><span class="nv">using</span><span class="p">:</span> <span class="o">.</span><span class="n">utf8</span><span class="p">)</span><span class="o">!</span>
<span class="k">let</span> <span class="nv">rsaJWTDecoder</span> <span class="o">=</span> <span class="kt">JWTDecoder</span><span class="p">(</span><span class="nv">jwtVerifier</span><span class="p">:</span> <span class="kt">JWTVerifier</span><span class="o">.</span><span class="nf">rs256</span><span class="p">(</span><span class="nv">publicKey</span><span class="p">:</span> <span class="n">publicKey</span><span class="p">))</span>
<span class="k">do</span> <span class="p">{</span>
   <span class="k">let</span> <span class="nv">jwt</span> <span class="o">=</span> <span class="k">try</span> <span class="n">rsaJWTDecoder</span><span class="o">.</span><span class="nf">decode</span><span class="p">(</span><span class="kt">JWT</span><span class="o">&lt;</span><span class="kt">MyClaims</span><span class="o">&gt;.</span><span class="k">self</span><span class="p">,</span> <span class="nv">fromString</span><span class="p">:</span> <span class="n">exampleJWTString</span><span class="p">)</span>
<span class="p">}</span> <span class="k">catch</span> <span class="p">{</span>
   <span class="nf">print</span><span class="p">(</span><span class="s">"Failed to decode JWT: </span><span class="se">\(</span><span class="n">error</span><span class="se">)</span><span class="s">"</span><span class="p">)</span>
<span class="p">}</span>
</code></pre>

                        <a href="Classes/JWTDecoder.html" class="slightly-smaller">See more</a>
                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">JWTDecoder</span> <span class="p">:</span> <span class="kt">BodyDecoder</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
          </div>
        </section>

      </article>
    </div>
    <section class="footer">
      <p>&copy; 2020 <a class="link" href="https://github.com/Kitura/Swift-JWT" target="_blank" rel="external">IBM &amp; Kitura Project Contributors</a>. All rights reserved. (Last updated: 2020-11-25)</p>
      <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
    </section>
  </body>
</div>
</html>
